home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jdmorris@ix.netcom.com (Jason D. Morris)
- Newsgroups: comp.lang.c++
- Subject: Re: Exception: GPF and DIV by 0 ?
- Date: Wed, 13 Mar 1996 04:37:24 GMT
- Organization: Netcom
- Message-ID: <31465068.7122141@nntp.ix.netcom.com>
- References: <3145D33E.208A@ios.chalmers.se>
- NNTP-Posting-Host: pon-mi1-21.ix.netcom.com
- X-NETCOM-Date: Tue Mar 12 10:36:21 PM CST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- On Tue, 12 Mar 1996 19:40:46 +0000, Michael Sch=?iso-8859-1?Q?=F6n
- <ei39418@ios.chalmers.se>?= wrote:
-
- >Hello,
- >
- >Does anyone know how to catch the following exceptions in Borland C++ =
- >
- >4.52:
- >- General Protection Fault (GPF)
- >- Division by zero
- >
- >I would like to provide an error handler for these errors.
- >
- >#Solution 1 - does not work:
- >The following code 'should' catch it:
- >
- >try
- >{
- > // some C++ code - generates the above mentioned exceptions.
- >}
- >catch(...)
- >{
- > // This catch ALL statement does not catch the exceptions.
- > // Instead Windows report them.
- >}
- >#Solution 2 - does not work either:
- >// Connect an error handler function via the set_unexpected macro.
- >set_unexpected( My_Own_Error_Handler() )
- >
- >
- >Any ideas?
- >One solution for the division fault is to put an error handler on the DIV =
- >
- >interrupt, but that is not a good solution. There must be a better one.
- >
- >How do one catch a GPF exception?
-
- The exceptions you mention are *hardware* exceptions. C++ is designed
- to handle *software* exceptions. To trap hardware exceptions you one
- ANSI standard option, use a signal handler. If you are working on
- Win95 or NT you can use structured exception handling. In both cases,
- you're better off programming defensively to avoid such exceptions in
- the first place, rather than letting them happen and then trying to
- correct them.
-
- Jason
-
-